constructive algorithms data structures dp greedy sortings strings *1900

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll signed long long
#define ld long double
#define to_low(s) transform(s.begin(), s.end(), s.begin(), ::tolower); // convert string to lowercase
#define to_up(s) transform(s.begin(), s.end(), s.begin(), ::toupper);  // convert string to uppercase
/*------------------------------------------------------------------------------------------------------------------------------*/
int a[1000001];
void solve()
{
    string s;
    cin >> s;
    int res1 = 0;
    int res2 = 1;

    int b = 0;

    for(int i=0;i<s.length();++i)
    {
        if (s[i] == '(')
        {
            ++b;
            a[b] = i + 1;
        }
        else
        {
            --b;
            if (b >= 0)
            {
                int len = i + 1 - a[b];
                if (res1 < len)
                    res1 = len, res2 = 0;
                if (res1 == len)
                    ++res2;
            }
            else
            {
                b = 0;
                a[0] = i + 1;
            }
        }
    }

    cout << res1 << " " << res2 << endl;
}
/*------------------------------------------------------------------------------------------------------------------------------*/
int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1